package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Scanner;

public class Test4 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入一个类名");
        String className=scanner.nextLine();
        System.out.println("请输入一个方法名");
        String methodName=scanner.nextLine();


        Class cls=Class.forName(className);
        Object o = cls.newInstance();
        Method method=cls.getMethod(methodName);
        method.invoke(o);

    }
}
